//
//  LeftMeunViewController.m
//  MINFOBBS
//
//  Created by juvid on 13-11-18.
//  Copyright (c) 2013年 minfo. All rights reserved.
//

#import "LeftMeunViewController.h"
#import "MFSideMenuContainerViewController.h"
#import "DetectionSystemVersion.h"
#import "BindingPhone.h"
#import "UseSet.h"
#import "HistorySearch.h"
#import "WelcomePage.h"
#import "MyInformation.h"
#import "MyMessage.h"
#import "UIColor+expanded.h"
#import "Common.h"
#import "ChangPhone.h"
@interface LeftMeunViewController ()

@end

@implementation LeftMeunViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
//    [self.menuContainerViewController setMenuWidth:170];
    arrLeft=[[NSArray alloc]initWithObjects:@"基本信息",@"绑定手机",@"我的消息",@"设置",@"历史查询",@"欢迎页", nil];
    arrImg=[[NSArray alloc]initWithObjects:@"leftPhone",@"leftSet",@"leftSearch",@"leftWelcome", nil];
    [self SetBarTitle];
     self.tableView.backgroundColor=[UIColor colorWithHexString:@"0x434343"];
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-(void)viewDidAppear:(BOOL)animated{
    
//    NSLog(@"%f",self.view.frame.size.height);
}
-(void)viewWillAppear:(BOOL)animated{
//     [self.menuContainerViewController setMenuWidth:320.0f animated:YES];
}

-(void)SetBarTitle
{
    
//    UIView *vieHome=[[UIView alloc]initWithFrame:CGRectMake(5, 28, 320, 28)];
//    //    NSLog(@"1:%f",self.view.frame.size.width);
//    vieHome.backgroundColor=[UIColor clearColor];
//    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(35, 0, 100, 28)];
//    customLab.backgroundColor=[UIColor clearColor];
//    [customLab setTextColor:[UIColor whiteColor]];
//    customLab.textAlignment=NSTextAlignmentCenter;
//    [customLab setText:@"我的百事搜"];
//    customLab.font = [UIFont systemFontOfSize:18];
//    [vieHome addSubview:customLab];
//    UIImageView *imgHome=[[UIImageView alloc]initWithFrame:CGRectMake(5, 4, 20, 20)];
//    imgHome.image=[UIImage imageNamed:@"leftUser"];
//    [vieHome addSubview:imgHome];
//    //    [self.navigationController.view addSubview:vieHome];
//    self.navigationItem.titleView = vieHome;
    self.navigationItem.titleView=[[DetectionSystemVersion alloc]SetVieTitle:@"我的百事搜" Fram:CGRectMake(5, 28, self.view.frame.size.width, 28) ImageName:@"letfHead"];
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return arrLeft.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.backgroundColor=[UIColor clearColor];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleGray;
    UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(15, 13, 18, 18)];
   img.image=[UIImage imageNamed:[NSString stringWithFormat:@"letfCell%d",indexPath.row]];
    [img setClipsToBounds:YES];
    [img setContentMode:UIViewContentModeScaleAspectFit];
    [cell.contentView addSubview:img];
    
    UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(45, 12, 100, 20)];
   lab.textColor=[UIColor whiteColor];
    lab.font=[UIFont boldSystemFontOfSize:15];
    lab.backgroundColor=[UIColor clearColor];
     lab.text=[arrLeft objectAtIndex:indexPath.row];
    [cell.contentView addSubview:lab];
    // Configure the cell...
    
      UIImageView *imgLine=[[UIImageView alloc]initWithFrame:CGRectMake(0,43,self.view.frame.size.width   , 1)];
    imgLine.image=[UIImage imageNamed:@"leftCellLine"];
    //
       [cell.contentView addSubview:imgLine];

    return cell;
}

- (MFSideMenuContainerViewController *)menuContainerViewController {
    //    NSLog(@"第一个%@ 第二个%@",self.parentViewController,self.navigationController.parentViewController);
    return (MFSideMenuContainerViewController *)self.navigationController.parentViewController;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
        UIViewController *allControl;
    if (indexPath.row==0) {
         MyInformation *myInformation=[[MyInformation alloc]init];
         allControl=myInformation;
    }
    else if(indexPath.row==1){
        if ([[Common GetPhone] isEqual:@""]) {
            ChangPhone *changPhone=[[ChangPhone alloc]init];
            changPhone.isBing=YES;
             allControl=changPhone;
        }
        else{
         BindingPhone *bindingPhone=[[BindingPhone alloc]init];
         allControl=bindingPhone;
        }
    }
    else if(indexPath.row==2){
        MyMessage *myMessage=[[MyMessage alloc]init];
          allControl=myMessage;
    }
    else if(indexPath.row==3){
          UseSet *useSet=[[UseSet alloc]init];
        allControl=useSet;

    }
    else if(indexPath.row==4){
        HistorySearch *historySearch=[[HistorySearch alloc]init];

         allControl=historySearch;
    }
    else if(indexPath.row==5){
          WelcomePage *welcomePage=[[WelcomePage alloc]init];
        allControl=welcomePage;

    }
       UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:allControl];
     [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"barHeadImage"] forBarMetrics:UIBarMetricsDefault];
    nav.view.alpha=0;
   
    [self.menuContainerViewController addChildViewController:nav];
    [self.menuContainerViewController.view addSubview:nav.view];
    [self ShowPick:nav.view];
// [self.navigationController pushViewController:allControl animated:YES];
}
-(void)ShowPick:(UIView *)vieBounced{
    [UIView animateWithDuration:0.3
                          delay:0
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^(void){
                         vieBounced.alpha = 1.0;
                     }
                     completion:^(BOOL finished) {
                     }];
       
}


@end
